#include <stdio.h>

int n, m;
int dist[500][500];

int main ()
{
	int t;

	for (scanf("%d", &t); t > 0; t --)
	{
		scanf("%d%d", &n, &m);

		for (int i = 0; i < n; i ++)
			for (int j = 0; j < n; j ++)
				dist[i][j] = (i == j? 0 : -1);

		for (int i = 0; i < m; i ++)
		{
			int a, b, c;

			scanf("%d%d%d", &a, &b, &c);

			a --;
			b --;

			if (dist[a][b] == -1 || c < dist[a][b])
			{
				dist[a][b] = c;
				dist[b][a] = c;
			}
		}

		for (int k = 0; k < n; k ++)
			for (int i = 0; i < n; i ++)
				for (int j = 0; j < n; j ++)
					if (dist[i][k] != -1 && dist[k][j] != -1 && (dist[i][j] == -1 || dist[i][k] + dist[k][j] < dist[i][j]))
						dist[i][j] = dist[i][k] + dist[k][j];

		for (int i = 0; i < n; i ++)
			for (int j = 0; j < n; j ++)
				if (dist[i][j] == -1)
					dist[i][j] = 2147483647;

		int min = 2147473647, a = 0, b = 1;
		for (int i = 0; i < n; i ++)
			for (int j = i + 1; j < n; j ++)
			{
				int ma = 0;
				for (int k = 0; k < n; k ++)
					if (dist[i][k] > ma && dist[j][k] > ma)
						ma = dist[i][k] < dist[j][k]? dist[i][k] : dist[j][k];
				if (ma < min)
				{
					min = ma;
					a = i;
					b = j;
				}
			}
		
		printf("%d %d\n", a + 1, b + 1);
	}

	return 0;
}